package com.finger.oss.controller;

import com.finger.commonutils.R;
import com.finger.oss.service.OssService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
@Log4j2
@RestController
@RequestMapping("/eduoss/fileoss")
@CrossOrigin
public class OssController {

    @Autowired
    private OssService ossService;

    /**
     * 将传过来的图片上传到阿里云OSS对象存储
     * @param file 上传的图片
     * @return 图片在阿里云OSS上的存储路径
     */
    @PostMapping("/upload/avatar")
    public R uploadAvatar(MultipartFile file){

        try {
            String url = ossService.uploadTeacherAvatar(file);
            return R.ok().data("url",url);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error();
        }
    }


}
